import request from "@/utils/request";

import {LOGIN} from '@/constants/data-url-constants'
import {AxiosPromise, AxiosResponse} from "axios";

type LoginUser = {
  username: string,
  password: string
}

export type LoginParam = {
  grant_type: string
  username: string
  password: string
  refresh_token: string
}
export type TokenRes = {
  access_token: string
  refresh_token: string
  token_type: string
  userId: string
  username: string
}

//登陆
export function doLogin(data: LoginParam): AxiosPromise<TokenRes> {
  return request({
    url: '/oauth/token',
    method: 'post',
    params: data,
    headers: {
      Authorization:data?.grant_type=='share_code'?'Basic ZXMtcmVwb3J0LXNoYXJlOjEyMzQ1Ng==':'Basic ZXMtcmVwb3J0LWFkbWluLXdlYjoxMjM0NTY=', // 客户端信息Base64明文：es-report-admin-web:123456
    },
  });
}

export function doLogin11(user: LoginUser) {
  return request.post(LOGIN, user)
}


/**
 * 注销
 */
export function logout() {
  return request({
    url: '/oauth/logout',
    method: 'POST',
  });
}

/**
 * 获取当前用户信息
 */
export function getCurrUser() {
  return request({
    url: '/oauth/getCurrUser',
    method: 'GET',
  });
}
